#!/usr/bin/env python
# -*- coding:utf-8 -*-
import urllib.request
import threading
import time
import ssl
import os
from multiprocessing import Pool

def paqu(dd):
    index = 0
    while index < 10000:
        ssl._create_default_https_context = ssl._create_unverified_context
        url = "https://segmentfault.com/a/1190000016052125"
        header = {
            "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11"}
        request = urllib.request.Request(url, headers=header)
        reponse = urllib.request.urlopen(request).read()
        index += 1
        print("线程：%d，index%d"%(dd,index))
        length = len(threading.enumerate())
        print('当前运行的线程数为：%d' % length)


po=Pool(12) #定义一个进程池，最大进程数3
for i in range(0,13):
#Pool.apply_async(要调用的目标,(传递给目标的参数元祖,))
#每次循环将会用空闲出来的子进程去调用目标
  po.apply_async(paqu,(i,))

print("----start----")
po.close() #关闭进程池，关闭后po不再接收新的请求
po.join() #等待po中所有子进程执行完成，必须放在close语句之后
print("-----end-----")
